/*
 * Copyright (c) 2006-2021, RT-Thread Development Team
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author        Notes
 * 2021-10-17     Meco Man      first version
 * 2022-05-10     Meco Man      improve rt-thread initialization process
 */
#include <lvgl.h>

static lv_obj_t* img;

void lv_user_gui_init(void)
{
    /* display demo; you may replace with your LVGL application at here */
    // extern void lv_demo_calendar(void);
    // lv_demo_calendar();

    // extern void lv_demo_benchmark(void);
    // lv_demo_benchmark();

    extern void lv_demo_widgets(void);
    lv_demo_widgets();

    // extern void lv_demo_keypad_encoder(void);
    // lv_demo_keypad_encoder();

    // img = lv_img_create(lv_scr_act());
    // lv_img_set_src(img, "A:/spi/a3.bin");      
    // lv_img_set_src(img, "A:/spi/a3-16b.bmp");
    // lv_img_set_src(img, "A:/spi/a3.sjpg");       
}

void lv_user_show_pic(int argc , char** argv)
{
    /*lvgl-v9 ok*/
    /*lvgl-v8, bmp图片的ppb必须与LVGL中LV_COLOR_DEPTH设置一致，否则不能显示。这地方折腾了一天。*/
    /*我还是开启LVGL的LV_USE_LOG宏, 才发现的原因。*/
    /*显示jpg图像, 需要用lvgl提供的jpg_to_sjpg.py脚本将jpg图像转换为sjpg图像。*/
    /*bmp图像用开源工具magick, 转换命令magick a3.bmp -define bmp:subtype=RGB565 output.bmp*/
    if (argc != 2)
    {
        rt_kprintf("Usage: lv_user_show_pic A:/spi/a3.bin\n");
        rt_kprintf("Usage: lv_user_show_pic A:/spi/a3-16b.bmp\n");
        rt_kprintf("Usage: lv_user_show_pic A:/spi/a3.sjpg\n");        
        return;
    }
    rt_kprintf("picture name: %s\n", argv[1]);
    img = lv_img_create(lv_scr_act());
    lv_img_set_src(img, argv[1]);
}
MSH_CMD_EXPORT(lv_user_show_pic, lvgl show pictures);
